let prefabArray = [
    'food',
    'foodLock',
    'market',
    'menuItem',
    'shop',
    'shopStatus',
    'stockItem',
    'storeStock',
    'tipAlert',
    'toast',
    'fixShop',
    'msg',
    'rank'
]
let PrefabCache = {

}
let prefabPool = {
    food: [],
    foodLock: [],
    stockItem: [],
    rank: [],
}

function getPrefabPool(name){
    let prefabNode = prefabPool[name].get();
    if(prefabNode == null){
        prefabNode = cc.instantiate(PrefabCache[name]);
    }
    return prefabNode;
}
function putPrefabPool(name, node){
   prefabPool[name].put(node);
}
function initPrefab() {
   return new Promise((resolve, reject) => {
        let i = 1;
        prefabArray.forEach((val, index) => {
            cc.loader.loadRes("prefab/"+val,(error, res) => {
                if(error){
                    reject(error) ;
                }
                i++;
                PrefabCache[val] = res;
                if(i > prefabArray.length){
                    console.log(i)
                    resolve(true);
                }
            })
        })
        console.log("预制体")

        console.log(PrefabCache)
   })
}
function initPrefabPool() {
        for(let key in prefabPool){
            prefabPool[key] = new cc.NodePool();
            console.log(key)
            console.log(PrefabCache[key])
            for(let i = 0;i< 50;i++){
                let foodPrefab = cc.instantiate(PrefabCache[key]);
                prefabPool[key].put(foodPrefab);
            }
        }
        console.log(prefabPool)
       
    
}
module.exports = {
    prefabArray,//预制体
    PrefabCache,
    prefabPool,//对象池
    getPrefabPool,
    putPrefabPool,
    initPrefab,
    initPrefabPool
}